package com.demo.spring.event;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

@Component
public class MyApplicationEventPublisherAware implements ApplicationEventPublisherAware {
	
	private ApplicationEventPublisher applicationEventPublisher;
	
	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
		System.out.println("set applicationEventPublisher: " + applicationEventPublisher);
		this.applicationEventPublisher = applicationEventPublisher;
	}
	
	public boolean register(User user) {
		//用户注册
		System.out.println("[service]用户["  + user + "]注册成功！");
		//消息发布
		applicationEventPublisher.publishEvent(new UserRegisterEvent(this, user));		
		return true;
	}

}
